package com.IR.user.service;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.IR.shop.mapper.SiteMapper;
import com.IR.shop.po.Site;
import com.IR.shop.po.SiteExample;

import sun.net.www.content.audio.x_aiff;

/**
 * @author 单立鑫
 * @date 2018-09-07
 * */
@Service
public class ASiteBIZ {
	
	@Resource
	private SiteMapper sitemapper;
	@Resource
	private BSiteBIZ bbiz;
	
	/*把原来的默认地址修改为普通地址*/
	public void updateSiteScode0(Long userid) {
		SiteExample example=new SiteExample();
		SiteExample.Criteria c=example.createCriteria();
		c.andScodeEqualTo("默认");
		c.andUseridEqualTo(userid);		
		List<Site> l=sitemapper.selectByExample(example);
		for(Site s:l) {
			s.setScode("");
			sitemapper.updateByPrimaryKey(s);
		}
	}
	/*修改默认地址*/
	public void updateSiteScode1(Site site,Long userid) {
		site.setScode("默认");
		sitemapper.updateByPrimaryKey(site);
	}
	
	/*修改*/
	public void updateUserSite(Site site,int userid) {
		SiteExample example=new SiteExample();
		SiteExample.Criteria c=example.createCriteria();
		c.andUseridEqualTo(new Long(userid));
		sitemapper.updateByPrimaryKey(site);
	}
	
	/*删除*/
	public void deleteUserSite(int siteid,int userid) {
		SiteExample example=new SiteExample();
		SiteExample.Criteria c=example.createCriteria();
		c.andUseridEqualTo(new Long(userid));
		c.andSiteidEqualTo(siteid);
		sitemapper.deleteByExample(example);
		
	}
	
	/*添加*/
	public void saveUserSite(Site site) {
		//先查询有没有地址，没有设为默认地址
		/*List<Site> l=bbiz.showUserSite(site.getUserid());
		if(l!=null) {
			site.setScode("");
		}else {
			site.setScode("默认");
		}*/
		sitemapper.insert(site);
	}
	
	
}
